package com.tensquare.article.controller;

import com.tensquare.article.pojo.Comment;
import com.tensquare.article.service.CommentService;
import com.tensquare.common.entity.Result;
import com.tensquare.common.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author fangyu
 * @version v1.0.0
 * @date 2020/10/13 7:48 下午
 */
@RestController
@CrossOrigin
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @RequestMapping(method = RequestMethod.POST)
    public Result save(@RequestBody Comment comment) {
        commentService.add(comment);
        return new Result(true, StatusCode.OK, "提交成功");
    }

    /**
     * 根据文章ID查询评论列表
     * @param articleId 文章ID
     * @return Result
     */
    @RequestMapping(value="/article/{articleId}",method= RequestMethod.GET)
    public Result findByArticleId(@PathVariable String articleId){
        return new Result(true, StatusCode.OK, "查询成功", commentService.findByArticleId(articleId));
    }
}
